﻿#include <Windows.h>
#include "sharedMemory.h"

HANDLE CreateSharedMemory (KEY key, int size)
{
	return CreateFileMapping(INVALID_HANDLE_VALUE,	
 			NULL,				
 			PAGE_READWRITE,		
 			0,				
 			size,			
 			key);		
}

HANDLE OpenSharedMemory (KEY key)
{
	return OpenFileMapping(FILE_MAP_ALL_ACCESS,	
 			FALSE,			
 			key);	
 
}

void CloseSharedMemory (HANDLE hShMem)
{
	CloseHandle(hShMem);
}

LPVOID AttachSharedMemory (HANDLE hShMem)
{
	return  MapViewOfFile(hShMem,	
 			FILE_MAP_ALL_ACCESS,	
 			0,		
 			0,	
 			0);	
 
}

void DetachSharedMemory (Node *mem)
{
	UnmapViewOfFile(mem);
}